<?php

namespace App\Http\Resources;

use App\Models\CouponsConfig;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Carbon;
class CouponsResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
//        return parent::toArray($request);
        $data = [
            "id"=>$this->id,
            "title"=>$this->title,
            "descript"=>$this->descript,
            "created_at"=>$this->created_at->toDateString(),
            "end_date"=>$this->end_date,
            "type"=>$this->type,
            "type_name"=>CouponsConfig::$couponsTypeMap[$this->type],
            "is_used"=>$this->is_used,
            "is_used_name"=>$this->is_used ?"已使用":"未使用",
            "is_passed"=> (Carbon::now()->toDateString()>$this->end_date)?"1":"",
        ];
        return  $data;
    }
}
